package com.briup.corejava.day15;

/**
 * 复习线程的两种创建方式
 * 测试后台线程
 */
public class Test5 {
    public static void main(String[] args) {
        Thread t1 = new Thread("t1"){
            @Override
            public void run() {
                for(int i=1;i<=30;i++){
                    System.out.println(Thread.currentThread().getName()+": "+i);
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        };
        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                for(int i=100;i>=50;i--){
                    System.out.println(Thread.currentThread().getName()+": "+i);
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        },"t2");

        // 启动之前，设置t2为后台线程
        t2.setDaemon(true);
        // 启动之前，设置优先级
        t1.setPriority(1);
        t2.setPriority(10);
        t1.start();
        t2.start();
        System.out.println(Thread.currentThread().getName()+"线程结束");
    }
}
